home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / GETSEQ.C < prev    next >
C/C++ Source or Header  |  1991-11-09  |  3KB  |  80 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    g e t s e q . c                                                 */
  3. /*                                                                    */
  4. /*    Job sequence number routines for UUPC/extended                  */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. #include <stdio.h>
  8.  
  9. #include "lib.h"
  10. #include "hlib.h"
  11. #include "getseq.h"
  12.  
  13.  
  14. /*--------------------------------------------------------------------*/
  15. /*    g e t s e q                                                     */
  16. /*                                                                    */
  17. /*    Return next available sequence number for UUPC processing       */
  18. /*--------------------------------------------------------------------*/
  19.  
  20. long getseq()
  21. {
  22.    char seqfile[FILENAME_MAX];
  23.    FILE *seqfile_fp;
  24.    long seq;
  25.  
  26.    mkfilename(seqfile, confdir, SFILENAME);
  27.    printmsg(4, "getseq: opening %s", seqfile);
  28.    if ((seqfile_fp = FOPEN(seqfile, "r", TEXT)) != nil(FILE)) {
  29.       fscanf(seqfile_fp, "%ld", &seq);
  30.       fclose(seqfile_fp);
  31.    } else {
  32.       printmsg(0, "getseq: can't find %s, creating", seqfile);
  33.       seq = 1;
  34.    };
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*                       Update sequence number                       */
  38. /*--------------------------------------------------------------------*/
  39.  
  40.    printmsg(5, "getseq: seq#=%ld", seq);
  41.  
  42.    if ((seqfile_fp = FOPEN(seqfile, "w", TEXT)) != nil(FILE))
  43.    {
  44.       fprintf(seqfile_fp, "%ld\n", seq+1);
  45.       fclose(seqfile_fp);
  46.    }
  47.  
  48.    return seq;
  49.  
  50. } /*getseq*/
  51.  
  52. /*--------------------------------------------------------------------*/
  53. /*    J o b N u m b e r                                               */
  54. /*                                                                    */
  55. /*    Given a job sequence number, returns a character string for use */
  56. /*    in file names                                                   */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. char *JobNumber( long sequence )
  60. {
  61.       static char buf[4];
  62.       const long base = bflag[F_ONECASE] ? 36 : 62;
  63.       static const char set[] =
  64.          "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  65.       size_t count = sizeof buf - 1;
  66.  
  67.       buf[count] = '\0';
  68.  
  69.       sequence %= (base*base*base);
  70.  
  71.       while( count-- > 0 )
  72.       {
  73.          buf[count] = set[ sequence % base ];
  74.          sequence /= base ;
  75.       } /* while */
  76.  
  77.       return buf;
  78.  
  79. } /* JobNumber */
  80.